<!doctype html>



  


<html class="theme-next mist use-motion" lang="en">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="recommendation," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="本文主要介绍“集体智慧编程”第二章的内容，python环境为2.7,所有代码都在这里">
<meta property="og:type" content="article">
<meta property="og:title" content="recommendation-sequential">
<meta property="og:url" content="https://annashuo.github.io/2017/05/02/recommendation-sequential/index.html">
<meta property="og:site_name" content="Anna's Blog">
<meta property="og:description" content="本文主要介绍“集体智慧编程”第二章的内容，python环境为2.7,所有代码都在这里">
<meta property="og:image" content="https://github.com/Annashuo/hello-world/blob/master/u_data_head10.png?raw=true">
<meta property="og:image" content="https://github.com/Annashuo/hello-world/blob/master/u_item_head10.png?raw=true">
<meta property="og:updated_time" content="2017-05-02T08:40:57.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="recommendation-sequential">
<meta name="twitter:description" content="本文主要介绍“集体智慧编程”第二章的内容，python环境为2.7,所有代码都在这里">
<meta name="twitter:image" content="https://github.com/Annashuo/hello-world/blob/master/u_data_head10.png?raw=true">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"right","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://annashuo.github.io/2017/05/02/recommendation-sequential/"/>





  <title> recommendation-sequential | Anna's Blog </title><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  
<!-- hexo-inject:begin --><!-- hexo-inject:end --><script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '',
      xfbml      : true,
      version    : 'v2.6'
    });
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>



<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-105321506-1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?6f5ab2ef1e021070500f7228c830f3c6";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Anna's Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
    
      <p class="site-subtitle">My heart is in the work...</p>
    
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="https://annashuo.github.io/2017/05/02/recommendation-sequential/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="Anna">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.gif">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="Anna's Blog">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="Anna's Blog" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                recommendation-sequential
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-05-02T14:38:29-04:00">
                2017-05-02
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/STUDY/" itemprop="url" rel="index">
                    <span itemprop="name">STUDY</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/05/02/recommendation-sequential/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count fb-comments-count" data-href="https://annashuo.github.io/2017/05/02/recommendation-sequential/" itemprop="commentCount">0</span> comments
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>本文主要介绍“集体智慧编程”第二章的内容，python环境为2.7,所有代码都在<a href="https://github.com/Annashuo/hadoop_project/blob/master/recommendations.py" target="_blank" rel="external">这里</a></p>
<a id="more"></a>
<h3 id="数据介绍"><a href="#数据介绍" class="headerlink" title="数据介绍"></a>数据介绍</h3><h4 id="简单自建critics数据集"><a href="#简单自建critics数据集" class="headerlink" title="简单自建critics数据集"></a>简单自建critics数据集</h4><p>格式为 ‘人名’:{‘电影一’:评分一,’电影二’:评分二,…}</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">critics=&#123;&apos;Lisa Rose&apos;: &#123;&apos;Lady in the Water&apos;: 2.5, &apos;Snakes on a Plane&apos;: 3.5,</div><div class="line"> &apos;Just My Luck&apos;: 3.0, &apos;Superman Returns&apos;: 3.5, &apos;You, Me and Dupree&apos;: 2.5, </div><div class="line"> &apos;The Night Listener&apos;: 3.0&#125;,</div><div class="line">&apos;Gene Seymour&apos;: &#123;&apos;Lady in the Water&apos;: 3.0, &apos;Snakes on a Plane&apos;: 3.5, </div><div class="line"> &apos;Just My Luck&apos;: 1.5, &apos;Superman Returns&apos;: 5.0, &apos;The Night Listener&apos;: 3.0, </div><div class="line"> &apos;You, Me and Dupree&apos;: 3.5&#125;, </div><div class="line">&apos;Michael Phillips&apos;: &#123;&apos;Lady in the Water&apos;: 2.5, &apos;Snakes on a Plane&apos;: 3.0,</div><div class="line"> &apos;Superman Returns&apos;: 3.5, &apos;The Night Listener&apos;: 4.0&#125;,</div><div class="line">&apos;Claudia Puig&apos;: &#123;&apos;Snakes on a Plane&apos;: 3.5, &apos;Just My Luck&apos;: 3.0,</div><div class="line"> &apos;The Night Listener&apos;: 4.5, &apos;Superman Returns&apos;: 4.0, </div><div class="line"> &apos;You, Me and Dupree&apos;: 2.5&#125;,</div><div class="line">&apos;Mick LaSalle&apos;: &#123;&apos;Lady in the Water&apos;: 3.0, &apos;Snakes on a Plane&apos;: 4.0, </div><div class="line"> &apos;Just My Luck&apos;: 2.0, &apos;Superman Returns&apos;: 3.0, &apos;The Night Listener&apos;: 3.0,</div><div class="line"> &apos;You, Me and Dupree&apos;: 2.0&#125;, </div><div class="line">&apos;Jack Matthews&apos;: &#123;&apos;Lady in the Water&apos;: 3.0, &apos;Snakes on a Plane&apos;: 4.0,</div><div class="line"> &apos;The Night Listener&apos;: 3.0, &apos;Superman Returns&apos;: 5.0, &apos;You, Me and Dupree&apos;: 3.5&#125;,</div><div class="line">&apos;Toby&apos;: &#123;&apos;Snakes on a Plane&apos;:4.5,&apos;You, Me and Dupree&apos;:1.0,&apos;Superman Returns&apos;:4.0&#125;&#125;</div></pre></td></tr></table></figure>
<h4 id="MoviesLens数据集"><a href="#MoviesLens数据集" class="headerlink" title="MoviesLens数据集"></a>MoviesLens数据集</h4><p><a href="https://grouplens.org/datasets/movielens/" target="_blank" rel="external">官方下载链接</a><br>下载下来的文件解压后主要有两个文件比较有用，一个是u.data，内容大概如下</p>
<p><img src="https://github.com/Annashuo/hello-world/blob/master/u_data_head10.png?raw=true" alt="u.data"></p>
<p>四列分别为usrID, movieID, rating, timestamp，每一行分别对应一个用户对一个影片的评分</p>
<p>第二个文件是u.item，大概内容如下</p>
<p><img src="https://github.com/Annashuo/hello-world/blob/master/u_item_head10.png?raw=true" alt="u.item"></p>
<p>新建loadMovieLens方法用于加载数据</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">#注意将数据文件放在当前文件夹里的data文件夹下的movielens文件夹里</div><div class="line">def loadMovieLens(path=&apos;./data/movielens&apos;):</div><div class="line">  # Get movie titles</div><div class="line">  movies=&#123;&#125;</div><div class="line">  for line in open(path+&apos;/u.item&apos;):</div><div class="line">    (id,title)=line.split(&apos;|&apos;)[0:2]</div><div class="line">    movies[id]=title</div><div class="line">  </div><div class="line">  # Load data</div><div class="line">  prefs=&#123;&#125;</div><div class="line">  for line in open(path+&apos;/u.data&apos;):</div><div class="line">    (user,movieid,rating,ts)=line.split(&apos;\t&apos;)</div><div class="line">    prefs.setdefault(user,&#123;&#125;)</div><div class="line">    prefs[user][movies[movieid]]=float(rating)</div><div class="line">  return prefs</div></pre></td></tr></table></figure>
<h3 id="基于用户的协作型过滤（user-based-collabarative-filtering）"><a href="#基于用户的协作型过滤（user-based-collabarative-filtering）" class="headerlink" title="基于用户的协作型过滤（user-based collabarative filtering）"></a>基于用户的协作型过滤（user-based collabarative filtering）</h3><h4 id="相似度评价体系"><a href="#相似度评价体系" class="headerlink" title="相似度评价体系"></a>相似度评价体系</h4><h5 id="欧几里得距离评价"><a href="#欧几里得距离评价" class="headerlink" title="欧几里得距离评价"></a>欧几里得距离评价</h5><p>用属性构造偏好空间，两者在偏好空间中距离越近，说明两者的相似度越高。</p>
<p>比如对于以下的数据，计算Lisa Rose和Gene Seymour的欧几里得距离为<br>$Eu = sqrt((2.5-3.0)^2+(3.5-3.5)^2+(3.0-1.5)^2+(3.5-5.0)^2+(2.5-3.5)^2)$</p>
<p>欧几里得距离越小，说明两者相似度越高。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&apos;Lisa Rose&apos;: &#123;&apos;Lady in the Water&apos;: 2.5, &apos;Snakes on a Plane&apos;: 3.5,</div><div class="line"> &apos;Just My Luck&apos;: 3.0, &apos;Superman Returns&apos;: 3.5, &apos;You, Me and Dupree&apos;: 2.5, </div><div class="line"> &apos;The Night Listener&apos;: 3.0&#125;,</div><div class="line">&apos;Gene Seymour&apos;: &#123;&apos;Lady in the Water&apos;: 3.0, &apos;Snakes on a Plane&apos;: 3.5, </div><div class="line"> &apos;Just My Luck&apos;: 1.5, &apos;Superman Returns&apos;: 5.0, &apos;The Night Listener&apos;: 3.0, </div><div class="line"> &apos;You, Me and Dupree&apos;: 3.5&#125;,</div></pre></td></tr></table></figure>
<p>现在我们人为构建一个公式，$1/(1+sqrt(Eu))$，这一函数返回值介于0到1，返回1说明两者有完全一样的偏好</p>
<p>欧几里得距离评价函数sim_distance(prefs, person1, person2)如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">from math import sqrt</div><div class="line"></div><div class="line"># Returns a distance-based similarity score for person1 and person2</div><div class="line">def sim_distance(prefs,person1,person2):</div><div class="line">  # Get the list of shared_items</div><div class="line">  si=&#123;&#125;</div><div class="line">  for item in prefs[person1]: </div><div class="line">    if item in prefs[person2]: </div><div class="line">      si[item]=1</div><div class="line"></div><div class="line">  # if they have no ratings in common, return 0</div><div class="line">  if len(si)==0: return 0</div><div class="line"></div><div class="line">  # Add up the squares of all the differences</div><div class="line">  sum_of_squares=sum([pow(prefs[person1][item]-prefs[person2][item],2) </div><div class="line">                      for item in prefs[person1] if item in prefs[person2]])</div><div class="line"></div><div class="line">  return 1/(1+sum_of_squares)</div></pre></td></tr></table></figure>
<h5 id="皮尔逊相关度评价"><a href="#皮尔逊相关度评价" class="headerlink" title="皮尔逊相关度评价"></a>皮尔逊相关度评价</h5><p>对于随机变量X和Y，皮尔森相关系数的就是：(x和y的协方差) / (x的标准差∗y的标准差)，用于判断两组数的线性关系程度。相对于欧几里得距离评价法，皮尔逊相关度评价有一个明显的优点是，假如两个用户对相同的电影的评价是正相关的，但是始终有一个用户的评价比另一个偏高很多，运用欧氏距离，两个用户在偏好空间里可能距离是很远的，求得得相似度并不高，但是运用皮尔逊相关度评价，就可以得到两者相关性很高的结果，即相似度很高的结论。</p>
<p>皮尔逊相关度函数sim_pearson(prefs, p1, p2)如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line"># Returns the Pearson correlation coefficient for p1 and p2</div><div class="line">def sim_pearson(prefs,p1,p2):</div><div class="line">  # Get the list of mutually rated items</div><div class="line">  si=&#123;&#125;</div><div class="line">  for item in prefs[p1]: </div><div class="line">    if item in prefs[p2]: si[item]=1</div><div class="line"></div><div class="line">  # if they are no ratings in common, return 0</div><div class="line">  if len(si)==0: return 0</div><div class="line"></div><div class="line">  # Sum calculations</div><div class="line">  n=len(si)</div><div class="line">  </div><div class="line">  # Sums of all the preferences</div><div class="line">  sum1=sum([prefs[p1][it] for it in si])</div><div class="line">  sum2=sum([prefs[p2][it] for it in si])</div><div class="line">  </div><div class="line">  # Sums of the squares</div><div class="line">  sum1Sq=sum([pow(prefs[p1][it],2) for it in si])</div><div class="line">  sum2Sq=sum([pow(prefs[p2][it],2) for it in si])	</div><div class="line">  </div><div class="line">  # Sum of the products</div><div class="line">  pSum=sum([prefs[p1][it]*prefs[p2][it] for it in si])</div><div class="line">  </div><div class="line">  # Calculate r (Pearson score)</div><div class="line">  num=pSum-(sum1*sum2/n)</div><div class="line">  den=sqrt((sum1Sq-pow(sum1,2)/n)*(sum2Sq-pow(sum2,2)/n))</div><div class="line">  if den==0: return 0</div><div class="line"></div><div class="line">  r=num/den</div><div class="line"></div><div class="line">  return r</div></pre></td></tr></table></figure>
<h4 id="求相似用户"><a href="#求相似用户" class="headerlink" title="求相似用户"></a>求相似用户</h4><p>topMatches(prefs, person, n=5, similarity=sim_pearson)函数求得person和其他用户的similarity，规则是pearson相关度或欧几里得距离评价，返回前n个最相似的用户。</p>
<h4 id="推荐电影"><a href="#推荐电影" class="headerlink" title="推荐电影"></a>推荐电影</h4><p>基于用户的协作型过滤推荐电影的基本思路如下：</p>
<p>假如我们现在要给一个特定用户p1推荐电影，首先运用欧几里得距离规则或者皮尔逊相关度评价求p1和其他所有用户的相似度，用每一个相似度来对每一个用户对其看过的电影的评分进行加权，然后对于用户p1没看过的每一部电影，将评分加权值求和，对所有电影并进行排序得到电影的推荐排名。</p>
<p>该函数为getRecommendations(prefs, person, similarity=sim_pearson)</p>
<p>这里有一个可以降低准确度来提高运行速度的方法，就是得到p1和其他所有用户的相似度后，可以只选取相似度高的部分用户进行后面的加权求和操作。</p>
<h3 id="基于物品的协作型过滤（item-based-collaborative-filtering）"><a href="#基于物品的协作型过滤（item-based-collaborative-filtering）" class="headerlink" title="基于物品的协作型过滤（item-based collaborative filtering）"></a>基于物品的协作型过滤（item-based collaborative filtering）</h3><p>在上面基于用户的协作型过滤过程中，用topMatches函数可以求出每两个用户之间的相似度，那么相同的道理我们也可以求出每两部电影之间的相似度。只需要把原用户电影数据矩阵进行转置，就可以调用相同的topMatches函数。</p>
<p>求出所有电影之间两两相似度矩阵的函数为calculateSimilarItems(prefs,n)</p>
<p>基于物品的协作型过滤推荐电影的基本思路如下：</p>
<p>假如我们现在要给用户p1推荐电影，首先求出所有电影之间两两的相似度，对于用户p1他自己看过的每一部电影，用p1对该电影的评分和该电影与p1没看过的其他所有电影的相似度一一相乘，然后对于p1没看过的其他所有电影的加权评分值进行求和，并排序得到推荐电影排名。</p>
<p>该函数为getRecommendedItems(prefs,itemMatch,user)</p>
<p>这里同样有一个可以提高速度的地方，即只求出用户p1看过的电影和其他电影之间的相似度，不需要求所有电影两两之间的相似度。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/recommendation/" rel="tag"># recommendation</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/04/27/Ecosystem/" rel="next" title="Hadoop Ecosystem">
                <i class="fa fa-chevron-left"></i> Hadoop Ecosystem
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/08/24/linux常用指令/" rel="prev" title="linux常用指令">
                linux常用指令 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="fb-comments"
           data-href="https://annashuo.github.io/2017/05/02/recommendation-sequential/"
           data-numposts="10"
           data-width="100%"
           data-colorscheme="light">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Anna" />
          <p class="site-author-name" itemprop="name">Anna</p>
          <p class="site-description motion-element" itemprop="description">My heart is in the work...</p>
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">43</span>
                <span class="site-state-item-name">posts</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">6</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">12</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/Annashuo/Annashuo.github.io" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/u/1861044584?is_all=1" target="_blank" title="Weibo">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  Weibo
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#数据介绍"><span class="nav-number">1.</span> <span class="nav-text">数据介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#简单自建critics数据集"><span class="nav-number">1.1.</span> <span class="nav-text">简单自建critics数据集</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#MoviesLens数据集"><span class="nav-number">1.2.</span> <span class="nav-text">MoviesLens数据集</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#基于用户的协作型过滤（user-based-collabarative-filtering）"><span class="nav-number">2.</span> <span class="nav-text">基于用户的协作型过滤（user-based collabarative filtering）</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#相似度评价体系"><span class="nav-number">2.1.</span> <span class="nav-text">相似度评价体系</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#欧几里得距离评价"><span class="nav-number">2.1.1.</span> <span class="nav-text">欧几里得距离评价</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#皮尔逊相关度评价"><span class="nav-number">2.1.2.</span> <span class="nav-text">皮尔逊相关度评价</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#求相似用户"><span class="nav-number">2.2.</span> <span class="nav-text">求相似用户</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#推荐电影"><span class="nav-number">2.3.</span> <span class="nav-text">推荐电影</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#基于物品的协作型过滤（item-based-collaborative-filtering）"><span class="nav-number">3.</span> <span class="nav-text">基于物品的协作型过滤（item-based collaborative filtering）</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Anna</span>
</div>


<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  

  
      <!-- UY BEGIN -->
      <script type="text/javascript" src="http://v2.uyan.cc/code/uyan.js?uid="></script>
      <!-- UY END --><!-- hexo-inject:begin --><!-- Begin: Injected MathJax -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({"tex2jax":{"inlineMath":[["$","$"],["\\(","\\)"]],"skipTags":["script","noscript","style","textarea","pre","code"],"processEscapes":true},"TeX":{"equationNumbers":{"autoNumber":"AMS"}}});
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
      all[i].SourceElement().parentNode.className += ' has-jax';
    }
  });
</script>

<script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- End: Injected MathJax -->
<!-- hexo-inject:end -->
  




  
  

  
  


  

  

  


</body>
</html>
